-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Remove the old COLOR_MAP and replace with an Enum #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I also like the idea of having auto-completion and cleaner implementation of the constants. GraphScene.setup_axes(self)
# width of edges
self.x_axis.set_stroke(width=2)
self.y_axis.set_stroke(width=2)
# color of edges
self.x_axis.set_color(RED)
self.y_axis.set_color(YELLOW)
# Add x,y labels
func = TexMobject("\\sin\\theta")
var = TexMobject("\\theta")
func.set_color(BLUE)
var.set_color(PURPLE)
func.next_to(self.y_axis,UP)
var.next_to(self.x_axis,RIGHT+UP)
# Y labels
self.y_axis.label_direction = LEFT*1.5
self.y_axis.add_numbers(*[-1,1])
#Parametters of x labels
init_val_x = -3*PI/2
step_x = PI/2
end_val_x = 3*PI/2 I really like the visual highlighting of things like PI, LEFT, TOP, BLUE, PURPLE, and to easily changing them. Is there maybe a way to use and enums and simultaneously keep BLUE_D instead of Colors.blue_d.value? |
We could create aliases in the file containing the class Colors(Enum):
...
RED = Colors.red
BLUE = Colors.blue
... |
I agree, I kinda hate how it currently looks like with the So I say we do one of the following:
To be quite honest, this something.value business loos pretty bad to me |
With this approach: # Colors
class Colors(Enum):
"""A list of pre-defined colors."""
dark_blue = "#236B8E"
DARK_BLUE = Colors.dark_blue.value we have the highlighting AND auto-completion |
Ok so it seems like this is the state of things:
This PR is replacing @kolibril13's suggestion fixes both "con"s and keeps the "pro"! The only part I don't like about it is that if we keep the colors inside the So I suggest that we keep @kolibril13's suggestion but in a separate file called EDIT: tagging @PgBiel as he was one of the main supporters of the Enum. |
I agree with @kolibril13 .
This is better IMO. |
Just pushed some changes that reflect the discussion above. Please review! |
I have just an issue with that; so If I understood correctly there are two ways to access a color, which are
Isn't that inconsistent? Both or none of them should use (This is for me non-blocking), |
Thanks for taking a look. I agree it's inconsistent. In my mind, I think we should just support |
# Therefore, we also add each color as a global constant, in upper case, to the | ||
# locals() of this module | ||
COLOR_MAP = {n.upper(): c.value for n, c in Colors.__members__.items()} | ||
locals().update(COLOR_MAP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this approach, unfortunately, we don't get auto-completion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no! I didn't realize that. Thanks for catching that
I think this closes #81 |
If we do this, then I don't see a reason to use Tagging @PgBiel who was one of the main supporters of Enum. Thoughts? |
Marking as draft as this needs more discussion before it's merged. |
So this needs a bit of rethinking. Anybody have any thoughts? |
Closing in favor of #488 |
Closes #332. Long diff, but self explanatory.
One thing I don't like about the Enum Way (TM) is that this
becomes this
which is ugly IMO. But I think overall the Enum makes things nicer in general. What do you think?
EDIT: I tried deprecating the old colors instead of just removing them but it's actually quite the hassle to issue DeprecationWarnings for module-level attributes. So I removed them.
Note 1: the discussion in #332 also mentions converting colors into integers or into a new class. I've left those to a future PR.
Note 2: please do not review docstrings in this PR. Thanks.